window.addEventListener('load', function () {
    var LBox = document.querySelector('.little_box');
    var main = document.querySelector('.main');
    //main距离页面顶部的距离
    var mainTop = main.offsetTop;
    //LBox固定后距离页面顶部的距离 = LBox初始时距离顶部距离 - main距离顶部距离
    var LBoxTop = LBox.offsetTop;
    var flexTop = LBoxTop - mainTop;
    /* var floor = document.querySelector('.floor');
    var goBack = document.querySelector('.gpback');
    var floorTop = floor.offsetTop; */
    document.addEventListener('scroll', function () {
        if (window.pageYOffset >= mainTop) {
            LBox.style.position = 'fixed';
            LBox.style.top = flexTop + 'px';
        } else {
            LBox.style.position = 'absolute';
            LBox.style.top = '185px';
        }
        /* if (window.pageYOffset >= floorTop) {
            goBack.style.display = 'block';
        } else {
            goBack.style.display = 'none';
        } */
    })

    var arr_l = document.querySelector('.arr_l');
    var arr_r = document.querySelector('.arr_r');
    var focus = document.querySelector('.focus');
    focus.addEventListener('mouseenter', function () {
        arr_l.style.display = 'block';
        arr_r.style.display = 'block';
        ol.style.display = 'block';
        /*  clearInterval(timer);
         timer = null;  //清除定时器变量 */
    })
    focus.addEventListener('mouseleave', function () {
        arr_l.style.display = 'none';
        arr_r.style.display = 'none';
        ol.style.display = 'none';
        timer = setInterval(function () {
            //手动调用点击事件
            arr_r.click();
        }, 2000)
    })
    var ul = document.querySelector('.banner');
    var ol = document.querySelector('.circle');
    var focus = document.querySelector('.focus');
    var focusWidth = focus.offsetWidth;
    for (var i = 0; i < ul.children.length; i++) {
        var li = document.createElement('li');
        li.setAttribute('index', i);
        ol.appendChild(li);
        //点击小圆圈触发事件
        li.addEventListener('mouseenter', function () {
            for (var i = 0; i < ol.children.length; i++) {
                ol.children[i].className = '';
            }
            this.className = 'current';
            var index = this.getAttribute('index');
            animate(ul, -index * focusWidth);
        })
    }
    ol.children[0].className = 'current';
})